package com.nightpiter.view.drawer;

import java.util.Collection;

import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;

import com.nightpiter.model.MetroModel;
import com.nightpiter.model.objects.Station;
import com.nightpiter.model.objects.Transition;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * @author Ilya Shurigyn (honorik@gmail.com)
 */
public abstract class MetroDrawer {

	protected MetroModel model;

	private Rect bounds;

	protected float scale = 10;
	
	protected int offsetX = 0, offsetY = 0;

	public MetroDrawer(MetroModel model) {
		this.model = model;

		int minX = Integer.MAX_VALUE;
		int minY = Integer.MAX_VALUE;
		int maxX = Integer.MIN_VALUE;
		int maxY = Integer.MIN_VALUE;

		Point position;
		for (Station station : model.getStations()) {
			position = station.getPosition();
			int x = position.x;
			int y = position.y;
			if (x < minX) {
				minX = x;
			}
			if (y < minY) {
				minY = y;
			}
			if (x > maxX) {
				maxX = x;
			}
			if (y > maxY) {
				maxY = y;
			}
		}
		
		this.bounds = new Rect(minX, minY, maxX, maxY);
	}

	public Rect getBounds() {
		return this.bounds;
	}

	public void setScale(float scale) {
		this.scale = scale;
	}

	public void setOffset(int offsetX, int offsetY) {
		this.offsetX = offsetX;
		this.offsetY = offsetY;
	}

	protected float realX(float x) {
		return x * scale + offsetX;
	}

	protected float realY(float y) {
		return y * scale + offsetY;
	}

	public abstract void drawMetro(Canvas canvas);

	public abstract void selectStation(Station station, Canvas canvas);

	public abstract void showWay(Collection<Transition> transitions, Canvas canvas);

}
